package world.ztomorrow.common.utils;


import lombok.experimental.UtilityClass;
import world.ztomorrow.common.constant.ErrorCodeEnum;

import static world.ztomorrow.common.constant.ErrorCodeEnum.*;


@UtilityClass
public class FormatCheckUtils {

    /**
     * 手机号格式
     */
    public ErrorCodeEnum phoneFormat(String input) {
        if (input == null || input.isEmpty()) {
            return USER_PHONE_NULL;
        }
        if (!input.matches("^1[3|4|5|6|7|8|9][0-9]{9}$")) {
            return USER_PHONE_FORMAT_ERROR;
        }
        return null;
    }

    public ErrorCodeEnum passwordFormat(String input) {
        if (input == null || input.isEmpty()) {
            return USER_PASSWORD_NULL;
        }
        if (!input.matches("^[0-9a-zA-Z]{6,20}$")) {
            return USER_PASSWORD_FORMAT_ERROR;
        }
        return null;
    }

    public ErrorCodeEnum codeFormat(String input) {
        if (input == null || input.isEmpty()) {
            return USER_VERIFY_CODE_NULL;
        }
        if (!input.matches("^\\d{4}$")) {
            return USER_VERIFY_CODE_FORMAT_ERROR;
        }
        return null;
    }
}
